package com.pxx.file.controller;

import com.pxx.file.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author : Yoo19
 * @description :
 * @createDate : 2025/6/24 16:04 04
 */
@RestController
@RequestMapping("upload")
public class PictureController {

    @Autowired
    private PictureService pictureService;

    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file) {
        String url = pictureService.uploadImage(file);
        // 处理图片上传逻辑
        return ResponseEntity.ok(url);
    }

    @PostMapping("/deleteImage")
    public ResponseEntity<Void> deleteImage(@RequestBody Map<String,String> map){
        String url = map.get("url");
        //处理图片删除
        pictureService.deleteImage(url);
        return ResponseEntity.ok().build();
    }
}
